Introduction

According to Centers for Disease Control and Prevention, in 2015-2016, more than 12% of adults at the age of 20 and above in the United States have cholesterol levels higher than 240mg/ml. A high cholesterol level is one of the major risk factors for coronary heart disease, heart attack and stroke. While there are two types of cholesterol, low-density lipoprotein (LDL) is known as the “bad” one that leads to the buildup of cholesterol in arteries. The goal of this project is to explore factors that can affect the level of LDL in a human body, and the result is intended to help readers gain insights on how to balance the level of LDL in order to control/prevent cardiovascular diseases.

The analysis result shows that …

Data

The data analysis is performed with the NHANES 2015-2016 data. The dependent variable, the level of low-density lipoprotein (LDL), measured by mg/dl, is selected from the dataset Cholesterol - LDL & Triglycerides of the laboratory data. Since a high level of triglyceride is believed to be associated with a high level of LDL, it is included in the model as the independent variable. Triglyceride data is also obtained from Cholesterol - LDL & Triglycerides of the laboratory data. We also include blood pressure readings from Blood Pressure dataset of the examination data. According to the data description, some participants have multiple blood pressure readings. For simplicity, we use averaged systolic and diastolic blood pressure readings as blood pressure measurements for each individual. Averaged intakes of fat and cholesterol, computed using both the First and the Second Day Total Nutrient Intakes of the dietary data, are added as independent variables as well. To account for more individual differences, we also include gender, race and age from the Demographics Data, and height, weight and BMI information from Body Measures of the examination data as additional covariates. Furthermore, SEQN, the respondent sequence number, is utilized as the unique identifier to match responses for each respondent. Finally, we removed all rows containing missing values, and there are a total of 2503 observations available for further analysis.

Methods

We fit models using multiple linear regression techniques and then perform model selections to choose the model that best describes the level of LDL. For the very first model, we regress the dependent variable LDL on all predictors:

\(\mathbf{LDL}\) ~ \(\mathbf{age + race + gender + height + weight + BMI + fat + cholesterol + triglyceride + diastolic + systolic}\) (1)

Note that covariates gender and race are treated as categorical variables.

A check of the relationship between residuals and fitted values suggests a transformation for the dependent variable (shows non-linearity).

Residual plot of the full model

Residual plot of the full model

With the help of the Box-Cox test:

Box-Cox Transformation plot

Box-Cox Transformation plot

we identify that the square root transformation is the best choice.

We then fit a new linear model with the transformed dependent variable, \(\sqrt{LDL}\):

\(\mathbf{\sqrt{LDL}}\) ~ \(\mathbf{age + race + gender + height + weight + BMI + fat + cholesterol + triglycerides + diastolic + systolic}\) (2)

As the model has as many as 11 covariates and some of them are insignificant under t-test, we then use the stepwise selection technique to choose variables that best explain \(\sqrt{LDL}\).

Besides, we consider transformations upon predictors. Considering partial residual plots:

Partial Residual Plot

Partial Residual Plot

we find out that variables age and triglycerides violate the linear structure assumption. Both of these plots exhibit a quadratic form, so in addition to response variables in the full model (2) above, we add age2 and triglycerides2 to the linear regression model:

\(\mathbf{\sqrt{LDL}}\) ~ \(\mathbf{age + age^2 + race + gender + height + weight + BMI + fat + cholesterol + triglycerides + triglycerides^2 + diastolic + systolic}\) (3)

Just as the process before, we will execute the stepwise model selection technique to choose the most significant variables of this model.

Steps outlined above are carried out in R, Stata and Python. In R, we use the package data.table for data cleaning.

Core Analysis

R

Data Cleaning

## Group Project HTML
## Author: Huayu Li, huayuli@umich.edu
## Updated: Dec. 8 2019

#### Data cleaning using data.table 

## Libraries: -------------------------------------------------------------------------
library(data.table)
library(foreign)
library(tidyverse) 

## 80: --------------------------------------------------------------------------------

## Read the datasets
demo=data.table(read.xport("./Original Data/DEMO_I.XPT.txt"))
tot1=data.table(read.xport("./Original Data/DR1TOT_I.XPT.txt"))
tot2=data.table(read.xport("./Original Data/DR2TOT_I.XPT.txt"))
b_pres=data.table(read.xport("./Original Data/BPX_I.XPT.txt"))
ldl=data.table(read.xport("./Original Data/TRIGLY_I.XPT.txt"))
measure=data.table(read.xport("./Original Data/BMX_I.XPT.txt"))

## For each dataset, choose the proper variables and make 
## some transformation.

# For demo dataset, we choose seqn, gender, age and race variables
Demo=demo[,.(seqn=SEQN,gender=as.factor(RIAGENDR),
             age=RIDAGEYR,race=as.factor(RIDRETH3))]

# For dietary data, we choose seqn, intake fat, intake cholesterol
# for each day. 
TOT1=tot1[,.(seqn=SEQN,intake_fat1=DR1TTFAT,
             intake_chol1=DR1TCHOL)]
TOT2=tot2[,.(seqn=SEQN,intake_fat2=DR2TTFAT,
             intake_chol2=DR2TCHOL)]

## Next we will use the average intake of the two days into
## our model. The average step is as following:
intake_type=c('intake_fat1','intake_fat2','intake_chol1','intake_chol2')
TOT=TOT1%>%merge(.,TOT2,by='seqn',all=FALSE)
TOT=melt(TOT,measure=intake_type)[
    ,.(seqn,type=factor(variable,intake_type,c(rep('intake_fat',times=2),
                                               rep('intake_chol',times=2))),
       variable,value)  
    ][
      ,.(intake=mean(value,na.rm=TRUE)),by=.(seqn,type)
    ]
  
TOT=dcast(TOT,...~type,value.var=c('intake'))  

# For blood pressure, we choose seqn, systolic pressures and diastolic 
# pressures. We then use the average pressure as the final pressure.
pres_type=c(paste('sys',1:4,sep=''),paste('dia',1:4,sep=''))
B_pres=b_pres[,.(seqn=SEQN,sys1=BPXSY1,sys2=BPXSY2,sys3=BPXSY3,sys4=BPXSY4,
                 dia1=BPXDI1,dia2=BPXDI2,dia3=BPXDI3,dia4=BPXDI4)]
B_pres=melt(B_pres,measure=pres_type)[,
                                      .(seqn,type=factor(variable,pres_type,
                                                         c(rep('s',times=4),rep('d',times=4))),
                                        variable,pressure=value)
                                      ][
                                        ,.(pres=mean(pressure,na.rm=TRUE)),by=.(seqn,type)
                                        ]
B_pres=dcast(B_pres,...~type,value.var=c('pres'))[
  ,.(seqn,systolic=s,diastolic=d)
  ]

# For ldl dataset, we choose seqn, LDL-cholesterol and Triglyceride
# for mg/dL.
LDL=ldl[,.(seqn=SEQN,ldl=LBDLDL,triglycerides=LBXTR)]

# For body measure dataset, we choose weight height and bmi as our 
# variables.
Measure=measure[,.(seqn=SEQN,weight=BMXWT,height=BMXHT,bmi=BMXBMI)]


## Now merge the datasets into one whole, with the seqn as
## the merging label. By the way, some seqn labels 
## should be removed, for they are not included in LDL dataset.

Data=Demo%>%merge(.,TOT,by='seqn',all=FALSE)%>%
  merge(.,B_pres,by='seqn',all=FALSE)%>%
  merge(.,LDL,by='seqn',all=FALSE)%>%
  merge(.,Measure,by='seqn',all=FALSE)%>%
  na.omit()

Models

### Using this file for regression: ---------------------------------------------------

## Libraries: -------------------------------------------------------------------------
library(lme4)
library(MASS)
library(car)

## 80: --------------------------------------------------------------------------------

## Remove the seqn variable, and set gender and race as factor variables
DT=Data[,.(gender=as.factor(gender),age,race=as.factor(race),intake_fat,intake_chol,
         systolic,diastolic,ldl,triglycerides,weight,height,bmi)]

## First of all, we will fit the model with all variables, and then give 
## the residual plot of the model.
L1=lm(ldl~.,data=DT)
summary(L1)
## 
## Call:
## lm(formula = ldl ~ ., data = DT)
## 
## Residuals:
##      Min       1Q   Median       3Q      Max 
## -113.646  -22.757   -2.451   19.297  149.850 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   101.571467  44.874374   2.263   0.0237 *  
## gender2         1.171152   1.847729   0.634   0.5262    
## age             0.175782   0.038684   4.544 5.78e-06 ***
## race2           3.952555   2.414177   1.637   0.1017    
## race3           2.036991   2.093998   0.973   0.3308    
## race4           3.506045   2.285949   1.534   0.1252    
## race6           5.104577   2.738375   1.864   0.0624 .  
## race7           6.036927   3.880265   1.556   0.1199    
## intake_fat      0.005288   0.022726   0.233   0.8160    
## intake_chol    -0.001265   0.004397  -0.288   0.7736    
## systolic       -0.005915   0.045972  -0.129   0.8976    
## diastolic       0.401837   0.057452   6.994 3.41e-12 ***
## triglycerides   0.142759   0.011379  12.546  < 2e-16 ***
## weight          0.301651   0.266228   1.133   0.2573    
## height         -0.318111   0.269684  -1.180   0.2383    
## bmi            -0.595490   0.741391  -0.803   0.4219    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 33.34 on 2487 degrees of freedom
## Multiple R-squared:  0.1342, Adjusted R-squared:  0.129 
## F-statistic: 25.69 on 15 and 2487 DF,  p-value: < 2.2e-16
## Here we give the residual plot of the model
plot(L1$fitted.values,L1$residuals)

## Here, it seems that some transformations should be used upon ldl. Here
## we do the Box-Cox test.
boxcox(L1,plotit=TRUE,lambda=seq(0,1,1/100))
## Here it seems that lambda=0.5 is the best choice, that is, to use sqrt(ldl).
## Here we make the transformation and then do the regression again.
L2=lm(sqrt(ldl)~.,data=DT)
summary(L2)
## 
## Call:
## lm(formula = sqrt(ldl) ~ ., data = DT)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.1905 -1.0601  0.0021  1.0178  5.5148 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    1.005e+01  2.158e+00   4.658 3.36e-06 ***
## gender2        5.965e-02  8.886e-02   0.671   0.5021    
## age            8.429e-03  1.860e-03   4.531 6.15e-06 ***
## race2          1.830e-01  1.161e-01   1.576   0.1151    
## race3          8.270e-02  1.007e-01   0.821   0.4116    
## race4          1.305e-01  1.099e-01   1.187   0.2354    
## race6          2.302e-01  1.317e-01   1.748   0.0806 .  
## race7          2.744e-01  1.866e-01   1.470   0.1416    
## intake_fat     4.259e-04  1.093e-03   0.390   0.6968    
## intake_chol   -8.613e-05  2.115e-04  -0.407   0.6838    
## systolic      -3.532e-04  2.211e-03  -0.160   0.8731    
## diastolic      2.006e-02  2.763e-03   7.261 5.11e-13 ***
## triglycerides  6.538e-03  5.472e-04  11.948  < 2e-16 ***
## weight         1.492e-02  1.280e-02   1.165   0.2440    
## height        -1.644e-02  1.297e-02  -1.268   0.2050    
## bmi           -2.700e-02  3.566e-02  -0.757   0.4489    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.604 on 2487 degrees of freedom
## Multiple R-squared:  0.1327, Adjusted R-squared:  0.1275 
## F-statistic: 25.38 on 15 and 2487 DF,  p-value: < 2.2e-16
## There are too many variables in the regression model, so here we will do
## the model selection and choose the variables. Here we do both the forward
## and backward selections.
L3=step(L2,direction='both',trace=FALSE)
summary(L3)
## 
## Call:
## lm(formula = sqrt(ldl) ~ age + diastolic + triglycerides + weight + 
##     height, data = DT)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -6.2425 -1.0646  0.0056  1.0406  5.5286 
## 
## Coefficients:
##                 Estimate Std. Error t value Pr(>|t|)    
## (Intercept)    8.8488834  0.5771649  15.332  < 2e-16 ***
## age            0.0079968  0.0016065   4.978 6.87e-07 ***
## diastolic      0.0203065  0.0025879   7.847 6.28e-15 ***
## triglycerides  0.0064965  0.0005279  12.306  < 2e-16 ***
## weight         0.0049061  0.0017000   2.886  0.00394 ** 
## height        -0.0083689  0.0036375  -2.301  0.02149 *  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.603 on 2497 degrees of freedom
## Multiple R-squared:  0.1304, Adjusted R-squared:  0.1286 
## F-statistic: 74.87 on 5 and 2497 DF,  p-value: < 2.2e-16
## By the way, in the models before, we didn't consider transformations 
## upon predictors; in the coming part, we will consider adding some
## nonlinear terms.
crPlots(L2,layout=c(4,3))
## From the partial residual plots, we can find out that for triglycerides and age,
## some nonlinear transformation forms should be add. We add this term, and the
## regression result is as following:
L4=lm(sqrt(ldl)~gender+age+race+intake_fat+intake_chol+systolic+diastolic+
             weight+height+bmi+triglycerides+I(triglycerides^2)+I(age^2),data=DT)
summary(L4)
## 
## Call:
## lm(formula = sqrt(ldl) ~ gender + age + race + intake_fat + intake_chol + 
##     systolic + diastolic + weight + height + bmi + triglycerides + 
##     I(triglycerides^2) + I(age^2), data = DT)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.2795 -0.9630 -0.0056  0.9958  5.4639 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         1.155e+01  2.065e+00   5.593 2.47e-08 ***
## gender2            -7.780e-02  8.572e-02  -0.908  0.36421    
## age                 1.075e-01  8.753e-03  12.282  < 2e-16 ***
## race2               8.510e-02  1.109e-01   0.767  0.44310    
## race3               1.954e-01  9.673e-02   2.020  0.04349 *  
## race4               2.324e-01  1.053e-01   2.207  0.02739 *  
## race6               1.303e-01  1.258e-01   1.035  0.30054    
## race7               3.578e-01  1.782e-01   2.008  0.04472 *  
## intake_fat         -7.455e-05  1.043e-03  -0.071  0.94303    
## intake_chol        -1.705e-04  2.019e-04  -0.844  0.39857    
## systolic            3.840e-03  2.141e-03   1.794  0.07298 .  
## diastolic           6.303e-03  2.858e-03   2.206  0.02750 *  
## weight              2.520e-02  1.223e-02   2.060  0.03950 *  
## height             -3.457e-02  1.246e-02  -2.775  0.00556 ** 
## bmi                -7.122e-02  3.413e-02  -2.087  0.03703 *  
## triglycerides       2.150e-02  1.660e-03  12.953  < 2e-16 ***
## I(triglycerides^2) -5.019e-05  5.005e-06 -10.027  < 2e-16 ***
## I(age^2)           -1.138e-03  9.593e-05 -11.862  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.53 on 2485 degrees of freedom
## Multiple R-squared:  0.2114, Adjusted R-squared:  0.206 
## F-statistic:  39.2 on 17 and 2485 DF,  p-value: < 2.2e-16
## Just the same, do the model selection.
L5=step(L4,direction='both',trace=FALSE)
summary(L5)
## 
## Call:
## lm(formula = sqrt(ldl) ~ age + systolic + diastolic + weight + 
##     height + bmi + triglycerides + I(triglycerides^2) + I(age^2), 
##     data = DT)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -5.2347 -0.9663 -0.0208  1.0166  5.4756 
## 
## Coefficients:
##                      Estimate Std. Error t value Pr(>|t|)    
## (Intercept)         1.109e+01  2.011e+00   5.516 3.82e-08 ***
## age                 1.047e-01  8.550e-03  12.249  < 2e-16 ***
## systolic            4.101e-03  2.091e-03   1.961   0.0500 *  
## diastolic           6.455e-03  2.832e-03   2.279   0.0228 *  
## weight              2.636e-02  1.221e-02   2.159   0.0310 *  
## height             -3.121e-02  1.214e-02  -2.571   0.0102 *  
## bmi                -7.503e-02  3.398e-02  -2.208   0.0274 *  
## triglycerides       2.116e-02  1.620e-03  13.060  < 2e-16 ***
## I(triglycerides^2) -4.954e-05  4.948e-06 -10.011  < 2e-16 ***
## I(age^2)           -1.105e-03  9.325e-05 -11.849  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.53 on 2493 degrees of freedom
## Multiple R-squared:  0.2085, Adjusted R-squared:  0.2057 
## F-statistic: 72.98 on 9 and 2493 DF,  p-value: < 2.2e-16

Stata

Data Cleaning

* import demographic data
import sasxport "./Original Data/DEMO_I.XPT.txt", clear

* rename variables
rename riagendr gender
rename ridageyr age
rename ridreth3 race

* select variables of focus
keep seqn gender age race

* save the cleaned demographics data
save "./Xiru Lyu/Data/demo.dta", replace

* import diet (day 1) data
import sasxport "./Original Data/DR1TOT_I.XPT.txt", clear

* rename variables
rename dr1ttfat fat1
rename dr1tchol chol1

* select variables of interest
keep seqn fat1 chol1

* save the cleaned diet (day 1) dataset
save "./Xiru Lyu/Data/diet1.dta", replace

* import diet (day 2) data
import sasxport "./Original Data/DR2TOT_I.XPT.txt", clear

* rename variables
rename dr2ttfat fat2
rename dr2tchol chol2

* select variables of focus
keep seqn fat2 chol2

* save the cleaned diet (day 2) dataset
save "./Xiru Lyu/Data/diet2.dta", replace

* import LDL & triglyceride data
import sasxport "./Original Data/TRIGLY_I.XPT.txt", clear

* rename variables
rename lbdldl ldl
rename lbxtr triglyceride

* select variables of interest
keep seqn ldl trig

* save the cleaned cholesterol dataset
save "./Xiru Lyu/Data/ldl.dta", replace

* import blood pressure data
import sasxport "./Original Data/BPX_I.XPT.txt", clear

* rename variables
rename bpxsy1 sy1
rename bpxsy2 sy2
rename bpxsy3 sy3
rename bpxsy4 sy4
rename bpxdi1 di1
rename bpxdi2 di2
rename bpxdi3 di3
rename bpxdi4 di4

* compute averaged systolic and diastolic blood pressure for each participant
egen systolic = rowmean(sy1 sy2 sy3 sy4)
egen diastolic = rowmean(di1 di2 di3 di4)

* select variables of interest
keep seqn systolic diastolic

* save the cleaned blood pressure dataset
save "./Xiru Lyu/Data/bp.dta", replace

* import body measure data
import sasxport "./Original Data/BMX_I.XPT.txt", clear

* rename variables
rename bmxwt weight
rename bmxbmi bmi
rename bmxht height

* select variables of interest
keep seqn weight height bmi

* merge datasets by seqn
merge 1:1 seqn using "./Xiru Lyu/Data/demo.dta"
keep if _merge == 3
drop _merge
merge 1:1 seqn using "./Xiru Lyu/Data/diet1.dta"
keep if _merge == 3
drop _merge
merge 1:1 seqn using "./Xiru Lyu/Data/diet2.dta"
keep if _merge == 3
drop _merge
merge 1:1 seqn using "./Xiru Lyu/Data/bp.dta"
keep if _merge == 3
drop _merge
merge 1:1 seqn using "./Xiru Lyu/Data/ldl.dta"
keep if _merge == 3
drop _merge

* compute averaged intakes of fat and cholesterol
egen fat = rowmean(fat1 fat2)
egen chol = rowmean(chol1 chol2)

* drop extra columns
drop fat1 fat2 chol1 chol2

* drop rows with missing values
foreach var of varlist age bmi chol diastolic fat gender height ldl race ///
seqn systolic triglyceride weight{
drop if missing(`var')
}

* save the dataset for data analysis
save "./Xiru Lyu/Data/final.dta", replace

Models

* transform the dependent variable
generate ldl2 = sqrt(ldl)

* fit a multiple linear regression model
regress ldl2 age i.race i.gender bmi weight height diastolic systolic chol ///
fat trig
Regression Result of Full Model (2)

Regression Result of Full Model (2)

* backward selection
xi: stepwise, pr(.1): regress ldl2 age i.race i.gender bmi weight height ///
diastolic systolic chol fat triglyceride
Backward Selection Result of Full Model (2)

Backward Selection Result of Full Model (2)

* forward selection
xi: stepwise, pe(.1): regress ldl2 age i.race i.gender bmi weight height ///
diastolic systolioc chol fat triglyceride
Forward Selection Result of Full Model (2)

Forward Selection Result of Full Model (2)

To be consistent with the model selection result performed in R (reasons to be discussed)

* transform covariates
generate triglyceride2 = triglyceride^2
generate age2 = age^2

* fit a multiple linear regression model
regress ldl2 age age2 i.race i.gender bmi weight height diastolic systolic ///
chol fat triglyceride triglyceride2
Regression Result of Full Model (3)

Regression Result of Full Model (3)

* backward selection
xi: stepwise, pr(.05): regress ldl2 age age2 i.race i.gender bmi weight  ///
height diastolic systolic chol fat triglyceride triglyceride2
Backward Selection Result of Full Model (3)

Backward Selection Result of Full Model (3)

* forward selection
xi: stepwise, pe(.05): regress ldl2 age age2 i.race i.gender bmi weight ///
height diastolic systolic chol fat triglyceride triglyceride2
Forward Selection Result of Full Model (3)

Forward Selection Result of Full Model (3)

* compare AIC & BIC of two nested models
regress ldl2 age height weight diastolic triglyceride
estat ic
AIC for Model 2_a

AIC for Model 2_a

regress ldl2 age age2 height weight bmi diastolic systolic triglyceride ///
triglyceride2
estat ic
AIC for Model 2_b

AIC for Model 2_b

Python

Additional Analysis

R

## Additional Analysis: Some extra graphs

## Libraries: -------------------------------------------------------------------------
library(ggplot2)
library(gridExtra)

## 80: --------------------------------------------------------------------------------

Linear mixed model

## Before graphing, we will have the linear mixed model upon the dataset:
LM=lmer(ldl~age+intake_fat+intake_chol+systolic+diastolic+
          weight+height+bmi+triglycerides+(1|gender)+(1|race),data=DT)
summary(LM)
## Linear mixed model fit by REML ['lmerMod']
## Formula: ldl ~ age + intake_fat + intake_chol + systolic + diastolic +  
##     weight + height + bmi + triglycerides + (1 | gender) + (1 |      race)
##    Data: DT
## 
## REML criterion at convergence: 24691.1
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -3.3525 -0.6773 -0.0739  0.5917  4.4911 
## 
## Random effects:
##  Groups   Name        Variance Std.Dev.
##  race     (Intercept)    0.695  0.8337 
##  gender   (Intercept)    0.000  0.0000 
##  Residual             1111.545 33.3398 
## Number of obs: 2503, groups:  race, 6; gender, 2
## 
## Fixed effects:
##                 Estimate Std. Error t value
## (Intercept)   111.161885  43.863459   2.534
## age             0.175052   0.038036   4.602
## intake_fat      0.001994   0.022497   0.089
## intake_chol    -0.001512   0.004350  -0.348
## systolic       -0.009931   0.045057  -0.220
## diastolic       0.411477   0.056723   7.254
## weight          0.309732   0.265604   1.166
## height         -0.351071   0.264700  -1.326
## bmi            -0.630334   0.737863  -0.854
## triglycerides   0.141182   0.011105  12.714
## 
## Correlation of Fixed Effects:
##             (Intr) age    intk_f intk_c systlc distlc weight height bmi   
## age          0.073                                                        
## intake_fat   0.047  0.053                                                 
## intake_chol -0.011 -0.066 -0.596                                          
## systolic    -0.074 -0.458  0.027  0.015                                   
## diastolic    0.011  0.102 -0.063  0.033 -0.302                            
## weight       0.961  0.071  0.017 -0.012 -0.009  0.022                     
## height      -0.992 -0.054 -0.071  0.009 -0.003 -0.051 -0.963              
## bmi         -0.957 -0.081 -0.016  0.004 -0.003 -0.040 -0.991  0.955       
## triglycerds -0.073 -0.134  0.053 -0.039 -0.047 -0.081 -0.093  0.077  0.067
## convergence code: 0
## boundary (singular) fit: see ?isSingular

Graphing

## Graph 1: Some Diagnosis upon these models
### F1: Checking error assumptions--residual plots
R1=data.table(fitted_values=L2$fitted.values,residuals=L2$residuals)
R2=data.table(fitted_values=L3$fitted.values,residuals=L3$residuals)
R3=data.table(fitted_values=L4$fitted.values,residuals=L4$residuals)
R4=data.table(fitted_values=L5$fitted.values,residuals=L5$residuals)
rs1=ggplot(R1,aes(x=fitted_values,y=residuals))+geom_point(size=1,colour='blue')+
  labs(title='Model 1')
rs2=ggplot(R2,aes(x=fitted_values,y=residuals))+geom_point(size=1,colour='blue')+
  labs(title='Model 2')
rs3=ggplot(R3,aes(x=fitted_values,y=residuals))+geom_point(size=1,colour='blue')+
  labs(title='Model 3')
rs4=ggplot(R4,aes(x=fitted_values,y=residuals))+geom_point(size=1,colour='blue')+
  labs(title='Model 4') 
grid.arrange(rs1,rs2,rs3,rs4,nrow=2)

## Graph 2: QQ-plots of the models
par(mfrow=c(2,2))
qqnorm(R1$residuals, ylab="Residuals",main='Q-Q Plot of Model 1')
qqline(R1$residuals)
qqnorm(R2$residuals, ylab="Residuals",main='Q-Q Plot of Model 2')
qqline(R2$residuals)
qqnorm(R3$residuals, ylab="Residuals",main='Q-Q Plot of Model 3')
qqline(R3$residuals)
qqnorm(R4$residuals, ylab="Residuals",main='Q-Q Plot of Model 4')
qqline(R4$residuals)

## Graph 3: Partial Residual Plots upon Model 3 and 4
crPlots(L4,layout=c(3,3))

crPlots(L5)

## Graph 4: Relationships between ldl and gender/race.  We have the mean level of
## ldl between different gender and race (For CI, we will use the JackKnife 
## standard error.)
Mean_JK = function(x){
  lx=length(x)
  MX=matrix(rep(x,rep(lx-1,lx)),ncol=lx,byrow=TRUE)
  theta=colMeans(MX)
  mean_theta=mean(theta)
  std_theta={(lx-1)/lx*sum((theta-mean_theta)^2)}^(1/2)
  std_theta
}

Gend=DT[,.(gender,ldl)]
Race=DT[,.(race,ldl)]
MG=Gend[,.(mean_ldl=mean(ldl),l_ldl=mean(ldl)+qnorm(0.025)*Mean_JK(ldl),
           r_ldl=mean(ldl)+qnorm(0.975)*Mean_JK(ldl)),by=gender]
MR=Race[,.(mean_ldl=mean(ldl),l_ldl=mean(ldl)+qnorm(0.025)*Mean_JK(ldl),
           r_ldl=mean(ldl)+qnorm(0.975)*Mean_JK(ldl)),by=race]

gend=ggplot(Gend,aes(x=gender,y=ldl))+geom_point(size=1,colour='blue')+
  labs(title='ldl~gender')
race=ggplot(Race,aes(x=race,y=ldl))+geom_point(size=1,colour='blue')+
  labs(title='ldl~race') 
mean_gend=ggplot(MG,aes(x=gender,y=mean_ldl))+geom_point(shape=16,col='red')+
  geom_segment(data=MG,mapping=aes(x=gender,xend=gender,y=l_ldl,yend=r_ldl),
               col='blue')+
  labs(title = 'Mean level of ldl between genders')
mean_race=ggplot(MR,aes(x=race,y=mean_ldl))+geom_point(shape=16,col='red')+
  geom_segment(data=MR,mapping=aes(x=race,xend=race,y=l_ldl,yend=r_ldl),
               col='blue')+
  labs(title = 'Mean level of ldl between races')

grid.arrange(gend,race,mean_gend,mean_race,nrow=2)

Stata

qreg ldl2 triglyceride, quantile(0.05)
qreg ldl2 triglyceride, quantile(0.25)
qreg ldl2 triglyceride, quantile(0.5)
qreg ldl2 triglyceride, quantile(0.75)
qreg ldl2 triglyceride, quantile(0.90)

(attach the plot here?)

Python

Discussion

Results

Stata

Stepwise variable selection for our first full model, where sqrt transformation is only applied to the dependent variable, shows that a model with age, diastolic blood pressure, triglycerides, height and weight as independent variables best fits the data. Results show that height is negatively correlated with the fitted level of LDL, while other covariates are positively related.

Specifically, with other variables fixed, one year increase in age leads to approximately 0.008 unit of increase in \(\sqrt{ldl}\). One unit of increase in diastolic blood pressure can increase \(\sqrt{ldl}\) by 0.02 unit. One unit of increase in weight and triglycerides can bump up \(\sqrt{ldl}\) by .005 and .006 unit, respectively. Finally, one unit increase in height leads to approximately 0.008 unit of decrease in \(\sqrt{ldl}\). Overall, higher levels of age, diastolic blood pressure, weight, and/or triglycerides can cause higher risks of cardiovascular diseases.

Stepwise variable selection for our second full model, where sqrt transformation is applied to the dependent variable, and \(triglycerides^2\) and \(age^2\) are included as additional independent variables, shows that a model with age, \(age^2\), triglycerides, \(triglycerides^2\), diastolic blood pressure, systolic blood pressure, height, weight and bmi as independent variables best fits the data. It is shown that \(age^2\), height and \(trig^2\) and bmi are negatively related to the fitted level of LDL, while all other covariates are positively correlated.

R

Note that for R code, we will use data.table() package to mutating the data, and after mutating, we will focus on the analysis.

First of all, as for the regression model with \(\sqrt{ldl}\) as the response and other variables as predictors, we do the backward selection, and find out that variables age, diastolic, triglycerides, weight, height are selected, and they are all significant under t-test. In this model, variables age, diastolic, triglycerides and weight are positive correlated to the fitted level of ldl, while height is negative correlated: with other variables fixed, one year of age increase leads to 0.008 unit increase in \(\sqrt{ldl}\), and 1 unit diastolic increase leads to 0.02 unit increase in \(\sqrt{ldl}\); 1 unit increase in triglycerides leads to 0.006 unit increase in \(\sqrt{ldl}\), and for weight this will lead to 0.005 unit increase in \(\sqrt{ldl}\); for height, this will lead to 0.008 unit decrease in \(\sqrt{ldl}\). The \(R^2\) is 0.1304, and the residual standard error is 1.603.

For the regression model with \(age^2\) and \(triglycerides^2\), after model selection, we can find out that terms age, systolic, diastolic, weight, height, bmi, triglycerides, \(triglycerides^2\) and \(age^2\) are selected, and they are significant under t-test. The height bmi and the two square terms are negatively correlated with ldl, with other variables positively correlated with ldl. The residual standard error changes to 1.53, and the \(R^2\) increases to 0.2085, which means that this model performs better than the one without square terms.

For the linear mixed model, here we will use the package lme4 to analysis. According to the fitting result, the age, intake_fat, diastolic, weight and triglycerides are positively correlated, while the others are negatively correlated; the t-values of triglycerides, diastolic and age are really large, shows that they are important variables to this model. However, according to the random effects, the variance for race is 0.695, for gender is 0, and for residual is 1111.545, implies that the linear mixed model may not work really well.

For the additional analysis, we plot the residual plots and the QQ-plots, and the result shows that the regression models satisfy the assumptions of the OLS model. By the way, we plot the relationships between ldl and gender and race, and the plots shows that the ldl level of male is slightly higher than female from the whole, and the levels for female are more centerized. For race, the ldl level of Other Race is the highest from the whole, and Non-Hispanic Black is the lowest.

Python

Note for Python, we use pandas to merge and clean all the dataset.Because there is no package about step regression to help select variables, so we refer to some self-written forward step regression function based on adjusted R-square to select variables. For GLM regression, we import module sklearn.linear_model.LinearRegression. As for the result, to accord with my partners, when choose variables ‘LBXTR’(triglycerides level), ‘BPXSY’(systolic blood pressure), ‘BPXDI’(diastolic blood pressure), ‘FAT’(average fat intake), ‘CHOL’(average Cholesterol intake), ‘GENDER’, ‘AGE’,‘RACE’, ‘HEIGHT’, ‘WEIGHT’, ‘BMI’,‘LBXTR2’(LBXTRLBXTR), ‘AGE2’(AGEAGE), I got the same result, the forward select function showed me that the significant variables should include LBXTR LBXTR2 BPXDI AGE AGE2 RACE BPXSY HEIGHT CHOL with adjusted R-square being 0.20377. After regression within LinearRegression module, the regression R-square was 0.207806, which means these data can express around 20% of cholesterol level change. Correspondingly, the coefficients of these variables are 4.37936363e-01, -9.94588617e-04, 1.12071396e-01,2.09660709e+00, -2.20899498e-02, 9.69819194e-01, 8.32880449e-02, -1.07237225e-01, -3.73454180e-03.

However it seems that in python, there is no good way to set a variable factor, such as race. So to fix this problem, I used mixed model in module statsmodel, and the result showed that coefficients be:intercept 38.613, LBXTR 0.436, LBXTR2 -0.001,BPXDI 0.119, AGE 2.101, AGE2 -0.022, BPXSY 0.080, HEIGHT -0.108, CHOL -0.004, and Group Var 1.897.

And from the result, we can notice that first gender has no effect on cholesterol level(mg/dl), second height to some extent affect the level rather than weight, though we may have intuition that fatter people may have more cholesterol amount, it does not change the cholesterol density(mg/dl) and maybe that is why variable fat intake here barely have impactions. Besides though we might consider that intake will increase the relevant material level, here we see that cholesterol average intake in two days decrease the density of blood cholesterol, it might be because that two day records are not representative for a long term intake and adjust system may react to food intake in a short time just like blood glucose level in normal life, and the p-value for CHOL is the biggest 0.258 which means its true value could be zero. Third, we can notice that ‘BPXDI’(diastolic blood pressure) impact more than ‘BPXSY’(systolic blood pressure). Forth, with age increasing, the cholesterol density(mg/dl) will increase by 2mg/dl per year, but the increase rate will slow down for coefficient of AGE2 is negative.